import 'package:flutter/material.dart';
import 'package:github_client_app/blocs/bloc_exports.dart';
import 'package:github_client_app/models/task.dart';

class AddTaskScreen extends StatelessWidget {
  const AddTaskScreen({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    final controller = TextEditingController();
    return Padding(
      padding: const EdgeInsets.all(20),
      child: Column(
        children: [
          const Text(
            "Task Add",
            style: TextStyle(fontSize: 24, fontWeight: FontWeight.w500),
          ),
          const SizedBox(
            height: 10,
          ),
          TextField(
            controller: controller,
            autofocus: true,
            decoration: const InputDecoration(
                border: OutlineInputBorder(), labelText: "Task title"),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              TextButton(
                onPressed: () {
                  Navigator.pop(context);
                },
                child: const Text("Cancel"),
              ),
              ElevatedButton(
                onPressed: () {
                  var task = Task(title: controller.text);
                  context.read<TasksBloc>().add(AddTask(task: task));
                  Navigator.pop(context);
                },
                child: const Text("Add"),
              )
            ],
          ),
        ],
      ),
    );
  }
}
